#include "chasis.h"
#include "loadArea.h"
#include "../framework.h"

/*Vertexf Chasis::vertices[] = { Vertexf(0.0f,0.0f),Vertexf(-1.0f,0.0f),
							   Vertexf(-1.0f,-0.45f),Vertexf(-0.6f,-0.5f),
							   Vertexf(-0.4f,-1.0f),Vertexf(0.0f,-1.0f),
							   Vertexf(-0.58f,-0.55f),Vertexf(-0.18f,-0.55f),
							   Vertexf(-0.18f,-0.95f),Vertexf(-0.42f,-0.95f)};*/

Vertexf Chasis::vertices[] = { Vertexf(0.0f,0.0f),Vertexf(-1.0f,0.0f),
							   Vertexf(-1.0f,-0.45f),Vertexf(-0.6f,-0.5f),
							   Vertexf(-0.4f,-1.0f),Vertexf(0.0f,-1.0f),
							   Vertexf(-0.58f,-0.55f),Vertexf(-0.18f,-0.55f),
							   Vertexf(-0.18f,-0.95f),Vertexf(-0.42f,-0.95f)};

Chasis::Chasis(	Rectangle chasisRec,Rectangle loadAreaRec)
	:	SceneObject(chasisRec){
	this->objVertices.vertices = Chasis::vertices;
	this->objVertices.nVertices = nVertices;
	this->addObject(LoadArea::name(),new LoadArea(loadAreaRec));
}

Chasis::~Chasis(){
}

void Chasis::draw(){
	Framework& fr = Framework::instance();

	Colorf oldColor = fr.pipeline.getFillColor();
	fr.pipeline.pushMatrix();
		fr.pipeline.translate(this->dimensions.centerX(),this->dimensions.centerY());

		fr.pipeline.setFillColor(Colorf(1.0f,0.8754f,0.768));
		fr.pipeline.draw(Pipeline::POLYGON,vertices,6);
		LoadArea& la = dynamic_cast<LoadArea&>(this->findObject(LoadArea::name()));
		la.draw();

		fr.pipeline.pushMatrix();
			fr.pipeline.translate(this->dimensions.width()/2,this->dimensions.height()/2);
			fr.pipeline.escale(this->dimensions.width(),this->dimensions.height());
			fr.pipeline.draw(Pipeline::POLYGON,vertices,6);
			fr.pipeline.setFillColor(Colorf(1.0f,0.0f,0.0));
			fr.pipeline.draw(Pipeline::POLYGON,vertices+6,4);
		fr.pipeline.popMatrix();
	fr.pipeline.popMatrix();
	fr.pipeline.setFillColor(oldColor);
}

